import {ref} from "vue";
import {DrawData, NodeElement} from "./components/hada-canvas-poster/types";
// @ts-ignore
import HadaCanvasPosterH5 from "./components/hada-canvas-poster/HadaCanvasPosterH5.vue";
import {RulerLine} from "./ruler";

export const drawData = ref<DrawData>({
    width: 500,
    height: 500,
    nodeElements:[],
    faces:[]
})

export function getDrawDataNodes() {
    const nodes = [];
    function _run(node: NodeElement) {
        nodes.push(node);
        if (node.resourceType !== 'group') {
            return;
        }
        if (!node.children || node.children.length === 0) {
            return;
        }
        node.children.forEach((item)=>{
            _run(item);
        })
    }
    drawData.value.nodeElements.forEach((item)=>{
        _run(item);
    })

    return nodes;
}

/**
 * 当前选中元素列表
 */
export const currentNodeElements = ref<NodeElement[]>([]);

/**
 * 绘制历史数据
 */
export const historyDrawData = ref<{name:string,data:DrawData}[]>([]);

/**
 * 历史窗口显示
 */
export const showHistoryWindow = ref(true)


/**
 * 历史当前项
 */
export const curIndex = ref(0);

/**
 * 绘制元素
 */
export const hadaCanvas = ref<HadaCanvasPosterH5>('');
export const historyWindow = ref('');

export const setHadaCanvas = (_hadaCanvas: any) => {
    hadaCanvas.value = _hadaCanvas
}

export const setHistoryWindow = (ref: any) => {
    historyWindow.value = ref
}


/**
 * 当前显示元素列表
 */
export const showNodeElements = ref([]);

/**
 * 实际显示比例
 */
export const actualMultiple = ref(1);

export const showScale = ref(100);

export const rulerLines = ref<RulerLine[]>([]);

export const boxMoveXy = ref({x:0,y:0,moveStartX:0,moveStartY:0});//显示区域位置信息
